import { createStore, applyMiddleware } from 'redux'
import axios from 'axios'

// applyMiddleware  中间件(让redux中可以执行异步代码) 

// 纯函数
let reducer = (state, action) => {
    let NewState = JSON.parse(JSON.stringify(state))
    switch(action.type) {
        case 'ADD_COUNT':
            NewState.count += action.count
            return NewState
        // case 'SET_DATA':
        //     axios.get('https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata').then(res => {
        //         console.log(res)
        //         NewState.data = res.data
        //     })
        //     return NewState
    }
    return NewState
}

// axios
let initState = {
    count: 100,
    num: 999999,
    data: []
}

let store = createStore(reducer, initState)

export default store